package cl.uchile.sketchpad.persistance.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import cl.uchile.sketchpad.persistance.model.Subject;

@Repository
public class SubjectDaoImpl implements SubjectDao {
	@PersistenceContext
	private EntityManager em; 

	@Override
	@Transactional(readOnly = true)
	public List<Subject> getAll() {
		TypedQuery<Subject> q = em.createQuery("from Subject s order by s.name", Subject.class);
		return q.getResultList();
	}

	@Override
	@Transactional(readOnly = true)
	public Subject findById(Integer id) {
		return em.find(Subject.class, id);
	}
	
}
